<!DOCTYPE html>
<html>
<head>
    <include file="Include:meta"/>
    <title>添加运营周报-目的地运营集团数据管理平台</title>
    <include file="Include:style"/>
</head>
<body>
<include file="Include:header"/>
<include file="Include:left"/>
<div id="main">
    <div class="crumbs">
        <div class="crumbs-text">项目 > [{$result['project_num']}]{$result['project_name']} > 运营周报 > 添加运营周报</div>
    </div>
    <div id="content">
        <form action="__APP__/CrmProjects/weekly_add" method="post" enctype="multipart/form-data">
            <input type="hidden" name="pid" value="{$result['pid']}">
            <input type="hidden" name="project_id" value="{$result['project_id']}">
            <div class="form-main">
                <div class="form-title">添加运营周报</div>
                <div class="form-item">
                    <div class="input-label"><span class="asterisk">*</span>周期</div>
                    <div class="input-item">
                        <select name="year" class="form-control w100" autocomplete="off">
                            <foreach name="year_list" item="vo">
                                <option value="{$vo}"
                                <if condition="$vo eq $year">selected</if>
                                >{$vo}</option>
                            </foreach>
                        </select>
                        年
                        <input type="hidden" value="" name="year_week">
                        <select name="week" id="week" class="form-control w250 ml10 required-select" autocomplete="off">
                            <option value="">请选择</option>
                            <foreach name="week_list" item="vo">
                                <option value="{$vo['num']}">{$vo['detail']}</option>
                            </foreach>
                        </select>
                        周
                        <span class="error-item">必填项</span>
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label"><span class="asterisk">*</span>本周工作</div>
                    <div class="input-item">
                        <textarea style="height: 150px" name="tswk" class="form-control w600 required-text"
                                  autocomplete="off"></textarea>
                        <span class="error-item">必填项</span>
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label"><span class="asterisk">*</span>下周计划</div>
                    <div class="input-item">
                        <textarea style="height: 150px" name="nxwk" class="form-control w600 required-text"
                                  autocomplete="off"></textarea>
                        <span class="error-item">必填项</span>
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label">心情状态</div>
                    <div class="input-item">
                        <for start="1" end="6">
                            <label class="radio-inline" for="mood{$i}">
                                <input type="radio" name="mood" id="mood{$i}" value="{$i}">{:get_mood($i)}
                            </label>
                        </for>
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label">问题描述</div>
                    <div class="input-item">
                        <textarea style="height: 150px" placeholder="需总部协调事宜或项目存在的问题" name="description"
                                  class="form-control w600 required-text"
                                  autocomplete="off"></textarea>
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label">附件</div>
                    <div class="input-item">
                        <div class="input-group w250 left">
                            <input type="text" name="file_name" class="form-control file-name" placeholder="请上传附件"
                                   readonly autocomplete="off">
                            <span class="input-group-btn">
								<button class="btn file-submit" type="button">上传</button>
							</span>
                        </div>
                        <button class="btn file-delete ml5 hide" type="button">删除</button>
                        <input type="hidden" name="file_url" class="file-url" autocomplete="off">
                        <span class="error-item">文件名必填</span>
                    </div>
                </div>

            </div>
            <div class="form-btn-item">
                <button class="btn submit" type="submit">提交</button>
                <button class="btn btn-default goback" type="button">返回</button>
            </div>
        </form>
    </div>
</div>
<include file="Include:javascript"/>
<script type="text/javascript">
    $(function () {
        KindEditor.ready(function (K) {
            //上传附件
            var editorFile = K.editor();
            $('.file-submit').on('click', function () {
                var parents = $(this).parents(".input-group");
                editorFile.loadPlugin('insertfile', function () {
                    document.cookie = "file_name=weekly";
                    document.cookie = "file_type=ppt,pptx,pdf,doc,docx,jpg,jpeg,png,xls,xlsx,txt,rar,zip";
                    editorFile.plugin.fileDialog({
                        clickFn: function (url, title) {
                            parents.nextAll(".error-item").hide();
                            parents.find(".file-name").val(title).prop("readonly", false);
                            parents.nextAll(".file-url").val(url);
                            parents.nextAll(".file-delete").show();
                            editorFile.hideDialog();
                        }
                    });
                });
            });
        });

        //删除附件
        $(".file-delete").click(function () {
            $(this).hide();
            $(this).nextAll(".error-item").hide();
            $(this).nextAll(".file-url").val("");
            $(this).prevAll(".input-group").find(".file-name").val("").prop("readonly", true);
            $(this).parents("tr").find(".required-text2").next(".error-item").hide();
        });
        ajaxWeek();//加载时默认显示当年每周日期
        //年联动周
        $("[name='year']").on("change", function () {
            ajaxWeek();
        });
        $("[name='week']").on("change", function () {
            var week_val = this.value;
            $("[name='year_week']").val($("#week option[value=" + week_val + "]").text());//获取第几周的详情
        });

        //ajax周
        function ajaxWeek() {
            var year = $("[name='year']").val(),
                pid = "{$result['pid']}";
            $.ajax({
                type: "POST",
                asnyc: true,
                dataType: "json",
                data: {"pid": pid, "year": year},
                url: "__APP__/CrmProjects/get_week_all",
                success: function (data) {
                    var option = "<option value=''>请选择</option>";
                    for (var x in data) {
                        option += "<option value=" + data[x].num + ">" + data[x].detail + "</option>";
                    }
                    $("[name='week']").html(option).trigger("change");
                }
            });
        }


        //提交验证
        $(".submit").on('click', function () {
            var week = $("select[name='week']").val();
            if (week.length == 0) {
                defeated_alert('请选择第几周');
                return false;
            }
            var tswk = $("textarea[name='tswk']").val();
            if (tswk.length == 0) {
                defeated_alert('请填写本周工作');
                return false;
            }
            var nxwk = $("textarea[name='nxwk']").val();
            if (nxwk.length == 0) {
                defeated_alert('请填写下周计划');
                return false;
            }
        });
    });
</script>
</body>
</html>